#include<iostream>
using namespace std;
#include<stack>
class NodeType {
public:
	int x;
	int y;
	NodeType(int a = 0, int b = 0) {
		x = a;
		y = b;
	}
	void print() {
		cout << '[' << x << ',' << y << ']';
	}
};
int main()
{
	int t;
	cin >> t;
	for (int i = 0; i < t; i++) {
		stack<NodeType> s;
		int n;
		cin >> n;
		int** p = new int* [n];
		for (int j = 0; j < n; j++) {
			p[j] = new int[n];
		}
		for (int j = 0; j < n; j++) {
			for (int k = 0; k < n; k++) {
				cin >> p[j][k];
			}
		}
		int x = 0;
		int y = 0;
		if (p[0][0] == 1 && p[1][1] == 1) {
			cout << "no path" << endl;
		}
		else {
			if (p[0][0] == 1) {
				x++;
				y++;
			}
			s.push((x, y));
			while (x < n && y < n) {
				if (y < n - 1 && p[x][y + 1] == 0) {
					y++;
				}
				else if (x < n - 1 && p[x + 1][y] == 0) {
					x++;
				}
				else if (y > 1 && p[x][y - 1] == 0) {
					y--;
				}
				else if (x > 1 && p[x - 1][y] == 0) {
					x--;
				}
				else {

				}
				s.push((x, y));
			}
		}
	}
	return 0;
}